// HTML加载完成才执行
function getEmailCaptcha () {
     $("#captcha-btn").click(function(event){
        const $this = $(this);
        event.preventDefault(); // 阻止默认 submit 事件
        const email = $("input[name='email']").val()
        $.ajax({
            url:"/auth/mail/captcha?email=" + email,
            method:"GET",
            success: function(result){
                console.log(result);
                if(result.code == 200){
                    $this.prop("disabled", true);
                    let countdown = 5;
                    const onInterval = setInterval(()=>{
                        $this.text(countdown)
                        countdown = countdown - 1
                        if(countdown <= 0){
                            $this.prop("disabled", false);
                            clearInterval(onInterval)
                            $this.text("获取验证码")
                            getEmailCaptcha()
                        }
                    },1000)
                }
            },
            error: function(error){
                console.log(error);
            }
        })
     })
}
$(function(){
    getEmailCaptcha()
})